package initializ

import (
	"fmt"
	"github.com/go-redis/redis"
	"week/appconfig"
)

func InitRedis() {
	config := appconfig.Conf.RedisConfig

	sprintf := fmt.Sprintf("%s:%d", config.Host, config.Port)

	client := redis.NewClient(&redis.Options{
		Addr:     sprintf,
		Password: config.Password, // no password set
		DB:       0,               // use default DB
	})

	pong, err := client.Ping().Result()
	if err != nil {
		fmt.Println("redis连接失败")

		return
	}

	fmt.Println(pong, "redis连接成功")
	// Output: PONG <nil>
}
